package com.gsmr.util;

import java.io.IOException;
import java.io.InputStream;
import java.text.DecimalFormat;
import java.util.List;

import com.gsmr.entity.*;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

import com.alibaba.druid.sql.visitor.functions.Substring;
import com.gsmr.controller.AlarmInfoController;

import net.sf.json.JSONObject;


public class ExcelUtil {

	public static final int maxExportRows = 50000;

	public static void fillExcelData_User(List<User> userList, Workbook wb, String[] headers) {
		int rowIndex = 0;
		String cur = null;
		Sheet sheet = wb.createSheet();
		Row row = sheet.createRow(rowIndex++);
		for (int i = 0; i < headers.length; i++) {
			row.createCell(i).setCellValue(headers[i]);
			}
		for (User user : userList) {
			if (rowIndex > maxExportRows + 1) {
				break;
			}
			row = sheet.createRow(rowIndex++);
			for (int j = 0; j < headers.length; j++) {
				switch (j) {
	                case 0: cur =  user.getId();break;
	                case 1: cur =  user.getPassword();break;
	                case 2: cur =  user.getFirstName();break;
	                case 3: cur =  user.getLastName();break;
	                case 4: cur =  user.getEmail();break;
				}
				row.createCell(j).setCellValue(cur);
			}
		}
	}

	public static String formatCell(HSSFCell hssfCell) {
		if (hssfCell == null) {
			return "";
		} else {
			if (hssfCell.getCellType() == HSSFCell.CELL_TYPE_BOOLEAN) {
				return String.valueOf(hssfCell.getBooleanCellValue());
			} else if (hssfCell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
				return String.valueOf(hssfCell.getNumericCellValue());
			} else {
				return String.valueOf(hssfCell.getStringCellValue());
			}
		}
	}

	public static String getIntegerPart(String str) {
		if (StringUtil.isEmpty(str)) {
			return "";
		}
		DecimalFormat decimalFormat = new DecimalFormat("###################.###########");
		return decimalFormat.format(Double.parseDouble(str));
	}

	public static Workbook fillExcelDataWithTemplate_User(List<User> userList, String templateFileName) throws IOException {
		InputStream inp = ExcelUtil.class.getResourceAsStream("/com/gsmr/template/" + templateFileName);
		POIFSFileSystem fs = new POIFSFileSystem(inp);
		Workbook wb = new HSSFWorkbook(fs);
		Sheet sheet = wb.getSheetAt(0);
		// 获取列数
		int cellNums = sheet.getRow(0).getLastCellNum();
		int rowIndex = 1;
		Row row = null;
		String cur = null;
		for (User user : userList) {
			if (rowIndex > maxExportRows + 1) break;
			
			row=sheet.createRow(rowIndex++);
			for(int j=0;j<cellNums;j++){
				switch(j){
                case 0: cur =  user.getId();break;
                case 1: cur =  user.getPassword();break;
                case 2: cur =  user.getFirstName();break;
                case 3: cur =  user.getLastName();break;
                case 4: cur =  user.getEmail();break;
            }
				row.createCell(j).setCellValue(cur);
			}
		}
		return wb;
	}
	
	public static void fillExcelData_SDCCH(List<SDCCH> sdcchList, Workbook wb, String[] headers) {
		int rowIndex = 0;
		String cur = null;
		Sheet sheet = wb.createSheet();
		Row row = sheet.createRow(rowIndex++);
		for (int i = 0; i < headers.length; i++) {
			row.createCell(i).setCellValue(headers[i]);
			}
		for (SDCCH sdcch : sdcchList) {
			if (rowIndex > maxExportRows + 1) {
				break;
			}
			row=sheet.createRow(rowIndex++);
			for(int j=0;j<headers.length;j++){
				switch(j){ 
                case 0: cur =  DateUtil.longToString(Long.parseLong(sdcch.getTimeStamp()),"yyyy-MM-dd HH:mm:ss SSS");break;
                case 1: cur =  sdcch.getFrontProcessorId();break;
                case 2: cur =  sdcch.getRecordId();break;
                case 3: cur =  sdcch.getIMSI();break;
                case 4: cur =  formatLogicChannel(sdcch.getLogicChannel());break;
                case 5: cur =  sdcch.getMSISDN();break;
                case 6: cur =  formatDirection(sdcch.getDirection());break;
                case 7: cur =  sdcch.getSiteName();break;
                case 8: cur =  sdcch.getDecode();break;
                case 9: cur =  sdcch.getCI();break;
                case 10: cur =  sdcch.getLAC();break;
                case 11: cur =  sdcch.getCTCS_ID();break;
                case 12: cur =  sdcch.getMS_TYPE();break;
                case 13: cur =  sdcch.getMessage_TYPE();break;
                case 14: cur =  sdcch.getTimeSlot();break;
                case 15: cur =  sdcch.getTMSI();break;
                case 16: cur =  sdcch.getChannel();break;
                case 17: cur =  sdcch.getTCH();break;
                case 18: cur =  sdcch.getL2();break;
                case 19: cur =  sdcch.getDataLength();break;
                case 20: cur =  sdcch.getSourceData();break;
                }
				row.createCell(j).setCellValue(cur);
			}
		}
	}
	
	public static Workbook fillExcelDataWithTemplate_SDCCH(List<SDCCH> sdcchList, String templateFileName) throws Exception {
		InputStream inp = ExcelUtil.class.getResourceAsStream("/com/gsmr/template/" + templateFileName);
		POIFSFileSystem fs = new POIFSFileSystem(inp);
		Workbook wb = new HSSFWorkbook(fs);
		Sheet sheet = wb.getSheetAt(0);
		// 获取列数
		int cellNums = sheet.getRow(0).getLastCellNum();
		int rowIndex = 1;
		Row row = null;
		String cur = null;
		for (SDCCH sdcch : sdcchList) {
			if (rowIndex > maxExportRows + 1) {
				break;
			}
			row = sheet.createRow(rowIndex++);
			for (int j = 0; j < cellNums; j++) {
				switch (j) {
                case 0: cur =  DateUtil.longToString(Long.parseLong(sdcch.getStartTime()),"yyyy-MM-dd HH:mm:ss SSS");break;
                case 1: cur =  sdcch.getFrontProcessorId();break;
                case 2: cur =  sdcch.getRecordId();break;
                case 3: cur =  sdcch.getIMSI();break;
                case 4: cur =  formatLogicChannel(sdcch.getLogicChannel());break;
                case 5: cur =  sdcch.getMSISDN();break;
                case 6: cur =  formatDirection(sdcch.getDirection());break;
                case 7: cur =  sdcch.getSiteName();break;
                case 8: cur =  sdcch.getDecode();break;
                case 9: cur =  sdcch.getCI();break;
                case 10: cur =  sdcch.getLAC();break;
                case 11: cur =  sdcch.getCTCS_ID();break;
                case 12: cur =  sdcch.getMS_TYPE();break;
                case 13: cur =  sdcch.getMessage_TYPE();break;
                case 14: cur =  sdcch.getTimeSlot();break;
                case 15: cur =  sdcch.getTMSI();break;
                case 16: cur =  sdcch.getChannel();break;
                case 17: cur =  sdcch.getTCH();break;
                case 18: cur =  sdcch.getL2();break;
                case 19: cur =  sdcch.getDataLength();break;
                case 20: cur =  sdcch.getSourceData();break;
                }
				row.createCell(j).setCellValue(cur);
			}
		}
		return wb;
	}
	
	public static void fillExcelData_FACCH(List<FACCH> facchList, Workbook wb, String[] headers) {
		int rowIndex = 0;
		String cur = null;
		Sheet sheet = wb.createSheet();
		Row row = sheet.createRow(rowIndex++);
		for (int i = 0; i < headers.length; i++) {
			row.createCell(i).setCellValue(headers[i]);
		}
		for (FACCH facch : facchList) {
			if (rowIndex > maxExportRows + 1) {
				break;
			}
			row = sheet.createRow(rowIndex++);
			for (int j = 0; j < headers.length; j++) {
				switch (j) {
                case 0: cur =  facch.getPrimaryKey();break;
                case 1: cur =  DateUtil.longToString(Long.parseLong(facch.getTimeStamp()),"yyyy-MM-dd HH:mm:ss SSS");break;
                case 2: cur =  DateUtil.longToString(Long.parseLong(facch.getStartTime()),"yyyy-MM-dd HH:mm:ss SSS");break;
                case 3: cur =  facch.getFrontProcessorId();break;
                case 4: cur =  facch.getRecordId();break;
                case 5: cur =  facch.getIMSI();break;
                case 6: cur =  formatLogicChannel(facch.getLogicChannel());break;
                case 7: cur =  facch.getMSISDN();break;
                case 8: cur =  formatDirection(facch.getDirection());break;
                case 9: cur =  facch.getFrameNumber();break;
                case 10: cur =  facch.getSiteName();break;
                case 11: cur =  facch.getDecode();break;
                case 12: cur =  facch.getRawMessage();break;
				case 13: cur = formatKilometer(facch.getKilometer());break;
                case 14: cur =  facch.getSpeed();break;
                case 15: cur =  facch.getCI();break;
                case 16: cur =  facch.getLAC();break;
                case 17: cur =  facch.getCTCS_ID();break;
                case 18: cur =  facch.getENGINE_ID();break;
                case 19: cur =  facch.getMS_TYPE();break;
                case 20: cur =  facch.getMessage_TYPE();break;
                case 21: cur =  facch.getSourceData();break;
                case 22: cur =  facch.getS_ARFCN();break;
                case 23: cur =  facch.getT_BSIC();break;
                case 24: cur =  facch.getT_BCCH();break;
                case 25: cur =  facch.getT_ARFCN();break;
                case 26: cur =  facch.getHO_Reference();break;
                case 27: cur =  facch.getTA();break;
                case 28: cur =  facch.getTimeSlot();break;
                case 29: cur =  facch.getTMSI();break;
                case 30: cur =  facch.getChannel();break;
                case 31: cur =  facch.getTCH();break;
                case 32: cur =  facch.getIMEI();break;
                case 33: cur =  facch.getL2();break;
                case 34: cur =  facch.getDataLength();break;
                case 35: cur =  facch.getLRBG();break;
                case 36: cur =  facch.getCRC_ECC();break;
                case 37: cur =  facch.getT_Train();break;
            }
				row.createCell(j).setCellValue(cur);
			}
		}
	}
	
	public static Workbook fillExcelDataWithTemplate_FACCH(List<FACCH> facchList, String templateFileName) throws Exception {
		InputStream inp = ExcelUtil.class.getResourceAsStream("/com/gsmr/template/" + templateFileName);
		POIFSFileSystem fs = new POIFSFileSystem(inp);
		Workbook wb = new HSSFWorkbook(fs);
		Sheet sheet = wb.getSheetAt(0);
		// 获取列数
		int cellNums = sheet.getRow(0).getLastCellNum();
		int rowIndex = 1;
		Row row = null;
		String cur = null;
		for (FACCH facch : facchList) {
			if (rowIndex > maxExportRows + 1) {
				break;
			}
			row = sheet.createRow(rowIndex++);
			for (int j = 0; j < cellNums; j++) {
				switch (j) {
                case 0: cur =  facch.getPrimaryKey();break;
                case 1: cur =  DateUtil.longToString(Long.parseLong(facch.getTimeStamp()),"yyyy-MM-dd HH:mm:ss SSS");break;
                case 2: cur =  DateUtil.longToString(Long.parseLong(facch.getStartTime()),"yyyy-MM-dd HH:mm:ss SSS");break;
                case 3: cur =  facch.getFrontProcessorId();break;
                case 4: cur =  facch.getRecordId();break;
                case 5: cur =  facch.getIMSI();break;
                case 6: cur =  formatLogicChannel(facch.getLogicChannel());break;
                case 7: cur =  facch.getMSISDN();break;
                case 8: cur =  formatDirection(facch.getDirection());break;
                case 9: cur =  facch.getFrameNumber();break;
                case 10: cur =  facch.getSiteName();break;
                case 11: cur =  facch.getDecode();break;
                case 12: cur =  facch.getRawMessage();break;
				case 13:
					cur = formatKilometer(facch.getKilometer());
					break;
                case 14: cur =  facch.getSpeed();break;
                case 15: cur =  facch.getCI();break;
                case 16: cur =  facch.getLAC();break;
                case 17: cur =  facch.getCTCS_ID();break;
                case 18: cur =  facch.getENGINE_ID();break;
                case 19: cur =  facch.getMS_TYPE();break;
                case 20: cur =  facch.getMessage_TYPE();break;
                case 21: cur =  facch.getSourceData();break;
                case 22: cur =  facch.getS_ARFCN();break;
                case 23: cur =  facch.getT_BSIC();break;
                case 24: cur =  facch.getT_BCCH();break;
                case 25: cur =  facch.getT_ARFCN();break;
                case 26: cur =  facch.getHO_Reference();break;
                case 27: cur =  facch.getTA();break;
                case 28: cur =  facch.getTimeSlot();break;
                case 29: cur =  facch.getTMSI();break;
                case 30: cur =  facch.getChannel();break;
                case 31: cur =  facch.getTCH();break;
                case 32: cur =  facch.getIMEI();break;
                case 33: cur =  facch.getL2();break;
                case 34: cur =  facch.getDataLength();break;
                case 35: cur =  facch.getLRBG();break;
                case 36: cur =  facch.getCRC_ECC();break;
                case 37: cur =  facch.getT_Train();break;
            }
				row.createCell(j).setCellValue(cur);
			}
		}
		return wb;
	}
	
	public static void fillExcelData_SACCH(List<SACCH> sacchList, Workbook wb, String[] headers) {
		int rowIndex = 0;
		String cur = null;
		Sheet sheet = wb.createSheet();
		Row row = sheet.createRow(rowIndex++);
		for (int i = 0; i < headers.length; i++) {
			row.createCell(i).setCellValue(headers[i]);
		}
		for (SACCH sacch : sacchList) {
			if (rowIndex > maxExportRows + 1)
				break;

			row = sheet.createRow(rowIndex++);
			for (int j = 0; j < headers.length; j++) {
				switch (j) {

                    case 0:
                        cur = DateUtil.longToString(Long.parseLong(sacch.getTimeStamp()), "yyyy-MM-dd HH:mm:ss SSS");
                        break;
                    case 1:
                        cur = sacch.getIMSI();
                        break;
                    case 2:
                        if(null!=sacch.getMSISDN()){
                            if(sacch.getMSISDN().equals("255")){
                                cur ="";
                                break;
                            }
                            cur =sacch.getMSISDN();
                            break;}else {cur =sacch.getMSISDN();
                            break;}
                    case 3:
                        cur = sacch.getCTCS_ID();
                        break;
                    case 4:
                        cur = sacch.getSiteName();
                        break;
                    case 5:
                        cur = sacch.getBCCH();
                        break;
                    case 6:
                        cur = sacch.getTCH();
                        break;
                    case 7:
                        cur = sacch.getTimeSlot();
                        break;
                    case 8:
                        cur = formatDirection1(sacch.getDirection());
                        break;
                    case 9:
                        cur = sacch.getFrameNumber();
                        break;
                    case 10:
                        cur = sacch.getMessage_TYPE();
                        break;
                    case 11:
                        cur = sacch.getRX_LEV_Full();
                        break;
                    case 12:
                        cur = sacch.getRX_QUAL_Full();
                        break;
                    case 13:
                        cur = sacch.getTA();
                        break;
                    case 14:
                        cur = sacch.getARFCNs();
                        break;
                    case 15:
                        cur = sacch.getFP_1000();
                        break;
                    case 16:
                        cur = sacch.getFP_1001();
                        break;
                    case 17:
                        cur = sacch.getFP_1002();
                        break;
                    case 18:
                        cur = sacch.getFP_1003();
                        break;
                    case 19:
                        cur = sacch.getFP_1004();
                        break;
                    case 20:
                        cur = sacch.getFP_1005();
                        break;
                    case 21:
                        cur = sacch.getFP_1006();
                        break;
                    case 22:
                        cur = sacch.getFP_1007();
                        break;
                    case 23:
                        cur = sacch.getFP_1008();
                        break;
                    case 24:
                        cur = sacch.getFP_1009();
                        break;
                    case 25:
                        cur = sacch.getFP_1010();
                        break;
                    case 26:
                        cur = sacch.getFP_1011();
                        break;
                    case 27:
                        cur = sacch.getFP_1012();
                        break;
                    case 28:
                        cur = sacch.getFP_1013();
                        break;
                    case 29:
                        cur = sacch.getFP_1014();
                        break;
                    case 30:
                        cur = sacch.getFP_1015();
                        break;
                    case 31:
                        cur = sacch.getFP_1016();
                        break;
                    case 32:
                        cur = sacch.getFP_1017();
                        break;
                    case 33:
                        cur = sacch.getFP_1018();
                        break;
                    case 34:
                        cur = formatKilometer(sacch.getKilometer());
                        break;
                    case 35:
                        cur = sacch.getSpeed();
                        break;
                    case 36:
                        cur = sacch.getDataLength();
                        break;
                    case 37:
                        cur = sacch.getLEVEL();
                        break;
                    case 38:
                        cur = sacch.getSNR();
                        break;
                    case 39:
                        cur = sacch.getQUALITY();
                        break;
                    case 40:
                        cur = sacch.getSourceData();
                        break;
                    case 41:
                        cur = sacch.getDecode();
                        break;
                    case 42:
                        cur = sacch.getMS_TYPE();
                        break;
                    case 43:
                        cur = sacch.getTMSI();
                        break;
                    case 44:
                        cur = sacch.getLAC();
                        break;
                    case 45:
                        cur = sacch.getCI();
                        break;
                    case 46:
                        cur = sacch.getFrontProcessorId();
                        break;
                    case 47:
                        cur = sacch.getRecordId();
                        break;
            }
				row.createCell(j).setCellValue(cur);
			}
		}
	}
	
	public static Workbook fillExcelDataWithTemplate_SACCH(List<SACCH> sacchList, String templateFileName) throws Exception {
		InputStream inp = ExcelUtil.class.getResourceAsStream("/com/gsmr/template/" + templateFileName);
		POIFSFileSystem fs = new POIFSFileSystem(inp);
		Workbook wb = new HSSFWorkbook(fs);
		Sheet sheet = wb.getSheetAt(0);
		// 获取列数
		int cellNums = sheet.getRow(0).getLastCellNum();
		int rowIndex = 1;
		Row row = null;
		String cur = null;
		for (SACCH sacch : sacchList) {
			if (rowIndex > maxExportRows + 1) {
				break;
			}
			row = sheet.createRow(rowIndex++);
			for (int j = 0; j < cellNums; j++) {
				switch (j) {
                case 0: cur =  DateUtil.longToString(Long.parseLong(sacch.getStartTime()),"yyyy-MM-dd HH:mm:ss SSS");break;
                case 1: cur =  sacch.getFrontProcessorId();break;
                case 2: cur =  sacch.getRecordId();break;
                case 3: cur =  sacch.getIMSI();break;
                case 4: cur =  sacch.getMSISDN();break;
                case 5: cur =  formatDirection(sacch.getDirection());break;
                case 6: cur =  sacch.getSiteName();break;
                case 7: cur =  sacch.getDecode();break;
                case 8: cur =  sacch.getBCCH();break;
                case 9: cur =  sacch.getCI();break;
                case 10: cur =  sacch.getLAC();break;
                case 11: cur =  sacch.getCTCS_ID();break;
                case 12: cur =  sacch.getMS_TYPE();break;
                case 13: cur =  sacch.getMessage_TYPE();break;
                /*
                case 14: cur =  sacch.getNCellLev1();break;
                case 15: cur =  sacch.getNCellLev2();break;
                case 16: cur =  sacch.getNCellLev3();break;
                case 17: cur =  sacch.getNCellLev4();break;
                case 18: cur =  sacch.getNCellLev5();break;
                case 19: cur =  sacch.getNCellLev6();break;
                case 20: cur =  sacch.getNCellLev7();break;
                case 21: cur =  sacch.getNCellLev8();break;
                */
                case 22: cur =  sacch.getRX_LEV_Full();break;
                case 23: cur =  sacch.getRX_LEV_Sub();break;
                case 24: cur =  sacch.getRX_QUAL_Full();break;
                case 25: cur =  sacch.getRX_QUAL_Sub();break;
                case 26: cur =  sacch.getARFCNs();break;
                /*
                case 27: cur =  sacch.getNCBCCH_BISC1();break;
                case 28: cur =  sacch.getNCBCCH_BISC2();break;
                case 29: cur =  sacch.getNCBCCH_BISC3();break;
                case 30: cur =  sacch.getNCBCCH_BISC4();break;
                case 31: cur =  sacch.getNCBCCH_BISC5();break;
                case 32: cur =  sacch.getNCBCCH_BISC6();break;
                case 33: cur =  sacch.getNCBCCH_BISC7();break;
                case 34: cur =  sacch.getNCBCCH_BISC8();break;
                */
                case 35: cur =  sacch.getTimeSlot();break;
                case 36: cur =  sacch.getTMSI();break;
                case 37: cur =  sacch.getTCH();break;
                case 38: cur =  sacch.getDataLength();break;
                case 39: cur =  sacch.getSourceData();break;
            }
				row.createCell(j).setCellValue(cur);
			}
		}
		return wb;
	}
	
	public static void fillExcelData_Decoding(List<Decoding> decodingList, Workbook wb, String[] headers) {
		int rowIndex = 0;
		String cur = null;
		Sheet sheet = wb.createSheet();
		Row row = sheet.createRow(rowIndex++);
		for (int i = 0; i < headers.length; i++) {
			row.createCell(i).setCellValue(headers[i]);
			}
		for (Decoding decoding : decodingList) {
			if (rowIndex > maxExportRows + 1) {
				break;
			}
			row=sheet.createRow(rowIndex++);
			for(int j=0;j<headers.length;j++){
				switch(j){
                case 0: cur =  decoding.getHdlc_id();break;
                case 1: cur =  DateUtil.longToString(Long.parseLong(decoding.getStartTime()),"yyyy-MM-dd HH:mm:ss SSS");break;
                case 2: cur =  decoding.getMSISDN();break;
                case 3: cur =  decoding.getIMSI();break;
                case 4: cur =  decoding.getCTCS_ID();break;
                case 5: cur =  decoding.getTrainNumber().equals("0")?"":decoding.getTrainNumber();break;
                case 6: cur =  decoding.getVicroadNumber().equals("null")?"":decoding.getVicroadNumber();break;
                case 7: cur =  decoding.getDeviceNumber();break;
                case 8: cur =  decoding.getPortNumber().equals("null")?"":decoding.getPortNumber();break;
                case 9: cur =  decoding.getTimeSlot();break;
                case 10: cur =  decoding.getRBCName().equals("null")?"":decoding.getRBCName();break;
                case 11: cur =  decoding.getRBCNumber().equals("0")?"":decoding.getRBCNumber();break;
                case 12: cur =  decoding.getQ_DIR().equals("null")?"":decoding.getQ_DIR();break;
                case 13: cur =  decoding.getCRCTest();break;
                case 14: cur =  decoding.getNID_LRBG();break;
                case 15: cur =  decoding.getQ_MPOSITION();break;
                case 16: cur =  decoding.getSpeed();break;
                case 17: cur =  decoding.getSignalType();break;
                case 18: cur =  decoding.getLLayer();break;
                case 19: cur =  decoding.getTLayer().equals("null")?"":decoding.getTLayer();break;
                case 20: cur =  decoding.getSLayer().equals("null")?"":decoding.getSLayer();break;
                case 21: cur =  formatSingalName(decoding.getALayer());break;
            }
				row.createCell(j).setCellValue(cur);
			}
		}
	}
	
	public static Workbook fillExcelDataWithTemplate_Decoding(List<Decoding> decodingList, String templateFileName) throws Exception {
		InputStream inp = ExcelUtil.class.getResourceAsStream("/com/gsmr/template/" + templateFileName);
		POIFSFileSystem fs = new POIFSFileSystem(inp);
		Workbook wb = new HSSFWorkbook(fs);
		Sheet sheet = wb.getSheetAt(0);
		// 获取列数
		int cellNums = sheet.getRow(0).getLastCellNum();
		int rowIndex = 1;
		Row row = null;
		String cur = null;
		for (Decoding decoding : decodingList) {
			if (rowIndex > maxExportRows + 1) {
				break;
			}
			row=sheet.createRow(rowIndex++);
			for(int j=0;j<cellNums;j++){
				switch(j){
                case 0: cur =  decoding.getHdlc_id();break;
                case 1: cur =  DateUtil.longToString(Long.parseLong(decoding.getStartTime()),"yyyy-MM-dd HH:mm:ss SSS");break;
                case 2: cur =  decoding.getMSISDN();break;
                case 3: cur =  decoding.getIMSI();break;
                case 4: cur =  decoding.getCTCS_ID();break;
                case 5: cur =  decoding.getTrainNumber().equals("0")?"":decoding.getTrainNumber();break;
                case 6: cur =  decoding.getVicroadNumber().equals("null")?"":decoding.getVicroadNumber();break;
                case 7: cur =  decoding.getDeviceNumber();break;
                case 8: cur =  decoding.getPortNumber().equals("null")?"":decoding.getPortNumber();break;
                case 9: cur =  decoding.getTimeSlot();break;
                case 10: cur =  decoding.getRBCName().equals("null")?"":decoding.getRBCName();break;
                case 11: cur =  decoding.getRBCNumber().equals("0")?"":decoding.getRBCNumber();break;
                case 12: cur =  decoding.getQ_DIR().equals("null")?"":decoding.getQ_DIR();break;
                case 13: cur =  decoding.getCRCTest();break;
                case 14: cur =  decoding.getNID_LRBG();break;
                case 15: cur =  decoding.getQ_MPOSITION();break;
                case 16: cur =  decoding.getSpeed();break;
                case 17: cur =  decoding.getSignalType();break;
                case 18: cur =  decoding.getLLayer();break;
                case 19: cur =  decoding.getTLayer().equals("null")?"":decoding.getTLayer();break;
                case 20: cur =  decoding.getSLayer().equals("null")?"":decoding.getSLayer();break;
				case 21:
					cur = formatSingalName(decoding.getALayer());
					break;
            }

				row.createCell(j).setCellValue(cur);
			}
		}
		return wb;
	}

	public static void fillExcelData_TCH(List<TCH> tchList, Workbook wb, String[] headers) {
		int rowIndex = 0;
		String cur = null;
		Sheet sheet = wb.createSheet();
		Row row = sheet.createRow(rowIndex++);
		for (int i = 0; i < headers.length; i++) {
			row.createCell(i).setCellValue(headers[i]);
			}
		for (TCH tch : tchList) {
			if (rowIndex > maxExportRows + 1) {
				break;
			}
			row=sheet.createRow(rowIndex++);
			for(int j=0;j<headers.length;j++){
				switch(j){
                case 0: cur = tch.getPrimaryKey();break;
                case 1: cur = DateUtil.longToString(Long.parseLong(tch.getTimeStamp()),"yyyy-MM-dd HH:mm:ss SSS");break;
                case 2: cur = DateUtil.longToString(Long.parseLong(tch.getStartTime()),"yyyy-MM-dd HH:mm:ss SSS");break;
                case 3: cur = tch.getFrontProcessorId();break;
                case 4: cur = tch.getRecordId();break;
                case 5: cur = formatLogicChannel(tch.getLogicChannel());break;
                case 6: cur = tch.getMSISDN();break;
                case 7: cur = formatDirection(tch.getDirection());break;
                case 8: cur = tch.getFrameNumber();break;
                case 9: cur = tch.getSiteName();break;
                case 10: cur = tch.getDecode();break;
                case 11: cur = tch.getRawMessage();break;
                case 12: cur = tch.getBCCH();break;
                case 13: cur = tch.getTCHData();break;
                case 14: cur = tch.getIMSI();break;
				case 15:
					cur = formatKilometer(tch.getKilometer());
					break;
                case 16: cur = tch.getSpeed();break;
                case 17: cur = tch.getCTCS_ID();break;
                case 18: cur = tch.getENGINE_ID();break;
                case 19: cur = tch.getCI();break;
                case 20: cur = tch.getLAC();break;
                case 21: cur = tch.getMS_TYPE();break;
                case 22: cur = tch.getMessage_TYPE();break;
                case 23: cur = tch.getSourceData();break;
                case 24: cur = tch.getTCH();break;
                case 25: cur = tch.getIMEI();break;
                case 26: cur = tch.getTA();break;
                case 27: cur = tch.getTCH_FRAME();break;
                case 28: cur = tch.getTimeSlot();break;
                case 29: cur = tch.getTMSI();break;
                case 30: cur = tch.getChannel();break;
                case 31: cur = tch.getHDLCData();break;
                case 32: cur = tch.getNPDUInfo();break;
                case 33: cur = tch.getHDLCMessage();break;
            }
				row.createCell(j).setCellValue(cur);
			}
		}
	}
	
	
	public static void fillExcelData_FScan(List<FScan> fscanList, Workbook wb, String[] headers) {
		int rowIndex = 0;
		String cur = null;
		Sheet sheet = wb.createSheet();
		Row row = sheet.createRow(rowIndex++);
		for (int i = 0; i < headers.length; i++) {
			row.createCell(i).setCellValue(headers[i]);
		}
		for (FScan fscan : fscanList) {
			if (rowIndex > maxExportRows + 1) break;
			
			row=sheet.createRow(rowIndex++);
			for (int j = 0; j < headers.length; j++) {
				switch (j) {
                case 0: cur =fscan.getScanTime();break;
				// { "扫描时间 ","前置机号 ","文件名编号 ","MCC","MNC","LAC","CID","BCCH","BSIC","RXLEV","TRXs"};
				//case 0: cur = fscan.getScanTime();break;
				case 1: cur = fscan.getFrontProcessorId(); break;
				case 2: cur = fscan.getBSName(); break;
				case 3: cur = fscan.getRecordId(); break;
				case 4: cur = fscan.getMCC(); break;
				case 5: cur = fscan.getMNC(); break;
				case 6: cur = fscan.getLAC(); break;
				case 7: cur = fscan.getCID(); break;
				case 8: cur = fscan.getBCCH(); break;
				case 9: cur = fscan.getBSIC(); break;
				case 10: cur = fscan.getRXLEV(); break;
				case 11: cur = fscan.getTRXs(); break;
				}
				row.createCell(j).setCellValue(cur);
			}
		}
	}
    public static void fillExcelHistoryData_FScan(List<FScan> fscanList, Workbook wb, String[] headers) {
        int rowIndex = 0;
        String cur = null;
        Sheet sheet = wb.createSheet();
        Row row = sheet.createRow(rowIndex++);
        for (int i = 0; i < headers.length; i++) {
            row.createCell(i).setCellValue(headers[i]);
        }
        for (FScan fscan : fscanList) {
            if (rowIndex > maxExportRows + 1) break;

            row=sheet.createRow(rowIndex++);
            for (int j = 0; j < headers.length; j++) {
                switch (j) {
                    case 0: cur =DateUtil.longToString(Long.parseLong(fscan.getScanTime()),"yyyy-MM-dd HH:mm:sss");break;
                    // { "扫描时间 ","前置机号 ","文件名编号 ","MCC","MNC","LAC","CID","BCCH","BSIC","RXLEV","TRXs"};
                    //case 0: cur = fscan.getScanTime();break;
                    case 1: cur = fscan.getFrontProcessorId(); break;
                    case 2: cur = fscan.getBSName(); break;
                    case 3: cur = fscan.getRecordId(); break;
                    case 4: cur = fscan.getMCC(); break;
                    case 5: cur = fscan.getMNC(); break;
                    case 6: cur = fscan.getLAC(); break;
                    case 7: cur = fscan.getCID(); break;
                    case 8: cur = fscan.getBCCH(); break;
                    case 9: cur = fscan.getBSIC(); break;
                    case 10: cur = fscan.getRXLEV(); break;
                    case 11: cur = fscan.getTRXs(); break;
                }
                row.createCell(j).setCellValue(cur);
            }
        }
    }

	public static void fillExcelData_TCHSignaling(List<TCH_Signaling> tchList, Workbook wb, String[] headers) {
		int rowIndex = 0;
		String cur = null;
		Sheet sheet = wb.createSheet();
		Row row = sheet.createRow(rowIndex++);
		for (int i = 0; i < headers.length; i++) {
			row.createCell(i).setCellValue(headers[i]);
		}
		for (TCH_Signaling tch : tchList) {
			if (rowIndex > maxExportRows + 1) break;
			
			row=sheet.createRow(rowIndex++);
			for (int j = 0; j < headers.length; j++) {
				switch (j) {
                case 0: cur = DateUtil.longToString(Long.parseLong(tch.getTimeStamp()),"yyyy-MM-dd HH:mm:ss SSS");break;
				case 1: cur = tch.getIMSI(); break;
                case 2: cur = tch.getMSISDN();break;
                case 3: cur = tch.getCTCS_ID();break;
                case 4: cur = tch.getSiteName();break;
                case 5: cur = tch.getBCCH();break;
                case 6: cur = tch.getTCH();break;
                case 7: cur = tch.getTimeSlot();break;
                case 8: cur = tch.getFrameNumber();break;
				case 9: cur = tchFormatDirection(tch.getDirection()); break;
                case 10: cur = tch.getSignalType();break;
                case 11: cur = formatSingalName(tch.getSignalName());break;
                case 12: cur = tch.getHDLC();break;
                case 13: cur = tch.getLLayer();break;
                case 14: cur = tch.getLLayer2();break;
                case 15: cur = formatLayer(tch.getNLayer());break;
                case 16: cur = formatLayer(tch.getTLayer());break;
                case 17: cur = formatLayer(tch.getSLayer());break;
				case 18: cur = formatSingalName(tch.getALayer());break;
                case 19: cur = tch.getCRCTest();break;
                case 20: cur = tch.getT_TRAIN();break;
                case 21: cur = tch.getLRBG();break;
				case 22:
					cur = formatKilometer(tch.getKilometer());
					break;
                case 23: cur = tch.getSpeed();break;
                case 24: cur = tch.getlength();break;
                    case 25: cur = tch.getLEVEL();break;
                    case 26: cur = tch.getSNR();break;
                    case 27: cur = tch.getQUALITY();break;
                case 28: cur = tch.getTCH_FRAME();break;
                case 29: cur = tch.getTMSI();break;
                case 30: cur = tch.getLAC();break;
                case 31: cur = tch.getCI();break;
                case 32: cur = tch.getFrontProcessorId();break;
                case 33: cur = tch.getRecordId();break;
				}
				row.createCell(j).setCellValue(cur);
			}
		}
	}
	
	public static Workbook fillExcelDataWithTemplate_TCH(List<TCH> tchList, String templateFileName) throws Exception {
		InputStream inp = ExcelUtil.class.getResourceAsStream("/com/gsmr/template/" + templateFileName);
		POIFSFileSystem fs = new POIFSFileSystem(inp);
		Workbook wb = new HSSFWorkbook(fs);
		Sheet sheet = wb.getSheetAt(0);
		// 获取列数
		int cellNums = sheet.getRow(0).getLastCellNum();
		int rowIndex = 1;
		Row row = null;
		String cur = null;
		for (TCH tch : tchList) {
			if (rowIndex > maxExportRows + 1) break;
			row = sheet.createRow(rowIndex++);
			for (int j = 0; j < cellNums; j++) {
				switch (j) {
                case 0: cur = tch.getPrimaryKey();break;
                case 1: cur = DateUtil.longToString(Long.parseLong(tch.getTimeStamp()),"yyyy-MM-dd HH:mm:ss SSS");break;
                case 2: cur = DateUtil.longToString(Long.parseLong(tch.getStartTime()),"yyyy-MM-dd HH:mm:ss SSS");break;
                case 3: cur = tch.getFrontProcessorId();break;
                case 4: cur = tch.getRecordId();break;
                case 5: cur = formatLogicChannel(tch.getLogicChannel());break;
                case 6: cur = tch.getMSISDN();break;
                case 7: cur = formatDirection(tch.getDirection());break;
                case 8: cur = tch.getFrameNumber();break;
                case 9: cur = tch.getSiteName();break;
                case 10: cur = tch.getDecode();break;
                case 11: cur = tch.getRawMessage();break;
                case 12: cur = tch.getBCCH();break;
                case 13: cur = tch.getTCHData();break;
                case 14: cur = tch.getIMSI();break;
				case 15:
					cur = formatKilometer(tch.getKilometer());
					break;
                case 16: cur = tch.getSpeed();break;
                case 17: cur = tch.getCTCS_ID();break;
                case 18: cur = tch.getENGINE_ID();break;
                case 19: cur = tch.getCI();break;
                case 20: cur = tch.getLAC();break;
                case 21: cur = tch.getMS_TYPE();break;
                case 22: cur = tch.getMessage_TYPE();break;
                case 23: cur = tch.getSourceData();break;
                case 24: cur = tch.getTCH();break;
                case 25: cur = tch.getIMEI();break;
                case 26: cur = tch.getTA();break;
                case 27: cur = tch.getTCH_FRAME();break;
                case 28: cur = tch.getTimeSlot();break;
                case 29: cur = tch.getTMSI();break;
                case 30: cur = tch.getChannel();break;
                case 31: cur = tch.getHDLCData();break;
                case 32: cur = tch.getNPDUInfo();break;
                case 33: cur = tch.getHDLCMessage();break;
            }
				row.createCell(j).setCellValue(cur);
			}
		}
		return wb;
	}
	public static void fillExcelData_Train_info(List<Train_info> train_infoList, Workbook wb, String[] headers) {
		int rowIndex = 0;
		String cur = null;
		Sheet sheet = wb.createSheet();
		Row row = sheet.createRow(rowIndex++);
		for (int i = 0; i < headers.length; i++) {
			row.createCell(i).setCellValue(headers[i]);
		}
		for (Train_info train_info : train_infoList) {
			if (rowIndex > maxExportRows + 1) {
				break;
			}
			row=sheet.createRow(rowIndex++);
			for(int j=0;j<headers.length;j++){
				switch(j){
                case 0: cur =  String.valueOf(train_info.getTrainId());break;
                case 1: cur =  train_info.getMSISDN();break;
                case 2: cur =  train_info.getIMSI();break;
                case 3: cur =  String.valueOf(train_info.getCTCS_ID());break;
                case 4: cur =  String.valueOf(train_info.getENGINE_ID());break;
            }
				row.createCell(j).setCellValue(cur);
			}
		}
	}

	public static Workbook fillExcelDataWithTemplate_Train_info(List<Train_info> train_infoList, String templateFileName) throws Exception {
		InputStream inp = ExcelUtil.class.getResourceAsStream("/com/gsmr/template/" + templateFileName);
		POIFSFileSystem fs = new POIFSFileSystem(inp);
		Workbook wb = new HSSFWorkbook(fs);
		Sheet sheet = wb.getSheetAt(0);
		// 获取列数
		int cellNums = sheet.getRow(0).getLastCellNum();
		int rowIndex = 1;
		Row row = null;
		String cur = null;
		for (Train_info train_info : train_infoList) {
			if (rowIndex > maxExportRows + 1) {
				break;
			}
			row=sheet.createRow(rowIndex++);
			for(int j=0;j<cellNums;j++){
				switch(j){
				case 0: cur =  String.valueOf(train_info.getTrainId());break;
                case 1: cur =  train_info.getMSISDN();break;
                case 2: cur =  train_info.getIMSI();break;
                case 3: cur =  String.valueOf(train_info.getCTCS_ID());break;
                case 4: cur =  String.valueOf(train_info.getENGINE_ID());break;
            }
				row.createCell(j).setCellValue(cur);
			}
		}
		return wb;
	}

	public static void fillExcelData_Balise_info(List<Balise_info> balise_infoList, Workbook wb, String[] headers) {
		int rowIndex = 0;
		String cur = null;
		Sheet sheet = wb.createSheet();
		Row row = sheet.createRow(rowIndex++);
		for (int i = 0; i < headers.length; i++) {
			row.createCell(i).setCellValue(headers[i]);
		}
		for (Balise_info balise_info : balise_infoList) {
			if (rowIndex > maxExportRows + 1) {
				break;
			}
			row=sheet.createRow(rowIndex++);
			for(int j=0;j<headers.length;j++){
				switch(j){
                case 0: cur =  String.valueOf(balise_info.getBaliseId());break;
                case 1: cur =  String.valueOf(balise_info.getNID_LRBG());break;
                case 2: cur =  String.valueOf(balise_info.getKilometer());break;
                case 3: cur =  String.valueOf(balise_info.getBalise_Name());break;
            }
				row.createCell(j).setCellValue(cur);
			}
		}
	}
	
//	public static void fillExcelDataBsInfo(List<BS_info> bsInfoList, Workbook wb, String[] headers) {
//		int rowIndex = 0;
//		String cur = null;
//		Sheet sheet = wb.createSheet();
//		Row row = sheet.createRow(rowIndex++);
//		for (int i = 0; i < headers.length; i++) {
//			row.createCell(i).setCellValue(headers[i]);
//		}
//		for (BS_info bsInfo : bsInfoList) {
//			if (rowIndex > maxExportRows + 1) {
//				break;
//			}
//			row=sheet.createRow(rowIndex++);
//			for(int j=0;j<headers.length;j++){
//				switch(j){
//                case 0: cur =  String.valueOf(bsInfo.getRegionId());break;
//                case 1: cur =  String.valueOf(bsInfo.getFrontProcessorId());break;
//                case 2: cur =  String.valueOf(bsInfo.getRouteName());break;
//                case 3: cur =  String.valueOf(bsInfo.getProvider());break;
//                case 4: cur =  String.valueOf(bsInfo.getBSName());break;
//                case 5: cur =  String.valueOf(bsInfo.getKilometerIndicator());break;
//                case 6: cur =  String.valueOf(bsInfo.getLatitude());break;
//                case 7: cur =  String.valueOf(bsInfo.getLongitude());break;
//                case 8: cur =  String.valueOf(bsInfo.getCGI());break;
//                case 9: cur =  String.valueOf(bsInfo.getLAC());break;
//                case 10: cur =  String.valueOf(bsInfo.getCI());break;
//                case 11: cur =  String.valueOf(bsInfo.getRAC());break;
//                case 12: cur =  String.valueOf(bsInfo.getBSIC());break;
//                case 13: cur =  String.valueOf(bsInfo.getCarrierFrequencyNumber());break;
//                case 14: cur =  String.valueOf(bsInfo.getBCCH());break;
//                case 15: cur =  String.valueOf(bsInfo.getTCH1());break;
//                case 16: cur =  String.valueOf(bsInfo.getTCH2());break;
//                case 17: cur =  String.valueOf(bsInfo.getTCH3());break;
//                case 18: cur =  String.valueOf(bsInfo.getOwnershipBSC());break;
//                case 19: cur =  String.valueOf(bsInfo.getBSGroupRing());break;
//                case 20: cur =  String.valueOf(bsInfo.getTrafficModle());break;
//                case 21: cur =  bsInfo.getIPAddress();break;
//                case 22: cur =  bsInfo.getFres();break;
//            }
//				row.createCell(j).setCellValue(cur);
//			}
//		}
//	}
public static void fillExcelDataBsInfo(List<BS_info> bsInfoList, Workbook wb, String[] headers) {
    int rowIndex = 0;
    String cur = null;
    Sheet sheet = wb.createSheet();
    Row row = sheet.createRow(rowIndex++);
    for (int i = 0; i < headers.length; i++) {
        row.createCell(i).setCellValue(headers[i]);
    }
    for (BS_info bsInfo : bsInfoList) {
        if (rowIndex > maxExportRows + 1) {
            break;
        }
        row=sheet.createRow(rowIndex++);
        for(int j=0;j<headers.length;j++){
            switch(j){
                case 0: cur =  String.valueOf(bsInfo.getRegionId());break;
                case 1: cur =  String.valueOf(bsInfo.getFrontProcessorId());break;
                case 2: cur =  String.valueOf(bsInfo.getRouteName());break;
                case 3: cur =  String.valueOf(bsInfo.getProvider());break;
                case 4: cur =  String.valueOf(bsInfo.getBSName());break;
                case 5: cur =  String.valueOf(bsInfo.getKilometerIndicator());break;
                case 6: cur =  String.valueOf(bsInfo.getLatitude());break;
                case 7: cur =  String.valueOf(bsInfo.getLongitude());break;
                case 8: cur =  String.valueOf(bsInfo.getCGI());break;
                case 9: cur =  String.valueOf(bsInfo.getLAC());break;
                case 10: cur =  String.valueOf(bsInfo.getCI());break;
                case 11: cur =  String.valueOf(bsInfo.getRAC());break;
                case 12: cur =  String.valueOf(bsInfo.getBSIC());break;
                case 13: cur =  String.valueOf(bsInfo.getCarrierFrequencyNumber());break;
                case 14: cur =  String.valueOf(bsInfo.getBCCH());break;
                case 15: cur =  String.valueOf(bsInfo.getTCH1());break;
                case 16: cur =  String.valueOf(bsInfo.getTCH2());break;
                case 17: cur =  String.valueOf(bsInfo.getTCH3());break;
                case 18: cur =  String.valueOf(bsInfo.getOwnershipBSC());break;
                case 19: cur =  String.valueOf(bsInfo.getBSGroupRing());break;
                case 20: cur =  String.valueOf(bsInfo.getTrafficModle());break;
                case 21: cur =  bsInfo.getIPAddress();break;
                case 22: cur =  bsInfo.getFres();break;
                case 23: cur =  String.valueOf(bsInfo.getEquipmentmanufacturer());break;
                case 24: cur =  String.valueOf(bsInfo.getModel());break;
                case 25: cur =  String.valueOf(bsInfo.getDeliverytime());break;
                case 26: cur =  String.valueOf(bsInfo.getMaintenancerecords());break;
            }
            row.createCell(j).setCellValue(cur);
        }
    }
}
	
	
	
	public static void fillExcelDataGPRSInfo(List<GPRSInfo> GPRSInfoList, Workbook wb, String[] headers) {
		int rowIndex = 0;
		String cur = null;
		Sheet sheet = wb.createSheet();
		Row row = sheet.createRow(rowIndex++);
		for (int i = 0; i < headers.length; i++) {
			row.createCell(i).setCellValue(headers[i]);
		}
		for (GPRSInfo info : GPRSInfoList) {
			if (rowIndex > maxExportRows + 1) {
				break;
			}
			row=sheet.createRow(rowIndex++);
			for(int j=0;j<headers.length;j++){
				switch(j){
                case 0: cur =  String.valueOf(info.getId());break;
                case 1: cur =  info.getVoiceCard();break;
                case 2: cur =  info.getDataCardMSISDN();break;
                case 3: cur =  info.getDataCardIMSI();break;
                case 4: cur =  info.getIpAddress();break;
                case 5: cur =  info.getEngineNo();break;
            }
				row.createCell(j).setCellValue(cur);
			}
		}
	}
	
	
	

	public static Workbook fillExcelDataWithTemplate_Balise_info(List<Balise_info> balise_infoList, String templateFileName) throws Exception {
		InputStream inp = ExcelUtil.class.getResourceAsStream("/com/gsmr/template/" + templateFileName);
		POIFSFileSystem fs = new POIFSFileSystem(inp);
		Workbook wb = new HSSFWorkbook(fs);
		Sheet sheet = wb.getSheetAt(0);
		// 获取列数
		int cellNums = sheet.getRow(0).getLastCellNum();
		int rowIndex = 1;
		Row row = null;
		String cur = null;
		for (Balise_info balise_info : balise_infoList) {
			if (rowIndex > maxExportRows + 1) {
				break;
			}
			row=sheet.createRow(rowIndex++);
			for(int j=0;j<cellNums;j++){
				switch(j){
				case 0: cur =  String.valueOf(balise_info.getBaliseId());break;
                case 1: cur =  String.valueOf(balise_info.getNID_LRBG());break;
                case 2: cur =  String.valueOf(balise_info.getKilometer());break;
                case 3: cur =  String.valueOf(balise_info.getBalise_Name());break;
            }
				row.createCell(j).setCellValue(cur);
			}
		}
		return wb;
	}

	public static void fillExcelData_AlarmInfo(List<AlarmInfo> alarmInfoList, Workbook wb, String[] headers) {
		int rowIndex = 0;
		String cur = null;
		Sheet sheet = wb.createSheet();
		Row row = sheet.createRow(rowIndex++);
		for (int i = 0; i < headers.length; i++) {
			row.createCell(i).setCellValue(headers[i]);
			}
		for (AlarmInfo alarmInfo : alarmInfoList) {
            if (rowIndex > maxExportRows + 1) {
				break;
			}
			row = sheet.createRow(rowIndex++);
			for (int j = 0; j < headers.length; j++) {
				switch(j){

                    case 0:
                        cur = String.valueOf(alarmInfo.getAlarmInfoId());
                        break;
                    case 1:
                        cur = AlarmInfoController.formatAlarmClass(alarmInfo.getAlarmType());
                        break;
                    case 2:
                        cur = alarmInfo.getAlarmObjectType();
                        break;
                    case 3:
                        cur = alarmInfo.getAlarmObjectInfo();
                        break;
                    case 4:
                        cur = AlarmInfoController.formatAlarmType(alarmInfo.getAlarmType());
                        break;
                    case 5: {
                        cur = setupTimestamp(alarmInfo.getAlarmTime(), alarmInfo.getAlarmDetails());
                        break;
                    }
                    case 6:
                        cur = alarmInfo.getLastTime()==0?"":DateUtil.longToString(alarmInfo.getLastTime(), "yyyy-MM-dd HH:mm:ss");
                        break;
                    case 7:
                        cur = String.valueOf(alarmInfo.getCount());
                        break;
                    case 8:
                        cur = alarmInfo.getEndTime()==0?"":DateUtil.longToString(alarmInfo.getEndTime(), "yyyy-MM-dd HH:mm:ss");
                        break;
                    case 9:
                        cur = alarmInfo.getComfirmTime()==0?"":DateUtil.longToString(alarmInfo.getComfirmTime(), "yyyy-MM-dd HH:mm:ss");
//                        cur = StringUtil.isNotEmpty(String.valueOf(alarmInfo.getConfirmTime())) ? DateUtil.longToString(alarmInfo.getConfirmTime(), "yyyy-MM-dd HH:mm:ss") : String.valueOf(alarmInfo.getConfirmTime());
                        break;
                    case 10:
                        cur = alarmInfo.getComfirmer();
                        break;
                    case 11:
                        cur = String.valueOf(alarmInfo.getAlarmDetails());
                        break;
				}
				row.createCell(j).setCellValue(cur);
			}
		}
	}

	public static void fillExcelData_HistoryAlarmInfo(List<AlarmInfo> alarmInfoList, Workbook wb, String[] headers) {
		int rowIndex = 0;
		String cur = null;
		Sheet sheet = wb.createSheet();
		Row row = sheet.createRow(rowIndex++);
		for (int i = 0; i < headers.length; i++) {
			row.createCell(i).setCellValue(headers[i]);
		}
		for (AlarmInfo alarmInfo : alarmInfoList) {
			if (rowIndex > maxExportRows + 1) {
				break;
			}
			row = sheet.createRow(rowIndex++);
			for (int j = 0; j < headers.length; j++) {
				switch (j) {
                    case 0:
                        cur = String.valueOf(alarmInfo.getAlarmInfoId());
                        break;
                    case 1:
                        cur = AlarmInfoController.formatAlarmClass(alarmInfo.getAlarmType());
                        break;
                    case 2:
                        cur = alarmInfo.getAlarmObjectType();
                        break;
                    case 3:
                        cur = alarmInfo.getAlarmObjectInfo();
                        break;
                    case 4:
                        cur = AlarmInfoController.formatAlarmType(alarmInfo.getAlarmType());
                        break;
                    case 5: {
                        cur = setupTimestamp(alarmInfo.getAlarmTime(), alarmInfo.getAlarmDetails());
                        break;
                    }
                    case 6:
                        cur = alarmInfo.getLastTime()==0?"":DateUtil.longToString(alarmInfo.getLastTime(), "yyyy-MM-dd HH:mm:ss");
                        break;
                    case 7:
                        cur = String.valueOf(alarmInfo.getCount());
                        break;
                    case 8:
                        cur = alarmInfo.getEndTime()==0?"":DateUtil.longToString(alarmInfo.getEndTime(), "yyyy-MM-dd HH:mm:ss");
                        break;
                    case 9:
                        cur = alarmInfo.getComfirmTime()==0?"":DateUtil.longToString(alarmInfo.getComfirmTime(), "yyyy-MM-dd HH:mm:ss");
//                        cur = StringUtil.isNotEmpty(String.valueOf(alarmInfo.getConfirmTime())) ? DateUtil.longToString(alarmInfo.getConfirmTime(), "yyyy-MM-dd HH:mm:ss") : String.valueOf(alarmInfo.getConfirmTime());
                        break;
                    case 10:
                        cur = alarmInfo.getComfirmer();
                        break;
                    case 11:
                        cur = String.valueOf(alarmInfo.getAlarmDetails());
                        break;
				}
				row.createCell(j).setCellValue(cur);
			}
		}
	}
	
	public static String setupTimestamp(Long time, String detail) {
		if (detail == null || detail.length() < 2 || !detail.startsWith("{")) {
			return DateUtil.longToString(time, "yyyy-MM-dd HH:mm:ss");
		}
		Object timestamp = JSONObject.fromObject(detail).get("timestamp");		
		if (timestamp != null && timestamp instanceof Integer) {
			Long time1 = Long.parseLong(timestamp.toString()) * 1000;
			if (time1 > 1) time = time1;
		}
		return DateUtil.longToString(time, "yyyy-MM-dd HH:mm:ss");
	}
    public static String setupTimestamp1(Long time) {
        return DateUtil.longToString(time, "yyyy-MM-dd HH:mm:ss");
    }

	public static Workbook fillExcelDataWithTemplate_AlarmInfo(List<AlarmInfo> alarmInfoList, String templateFileName) throws Exception {
		InputStream inp = ExcelUtil.class.getResourceAsStream("/com/gsmr/template/" + templateFileName);
		POIFSFileSystem fs = new POIFSFileSystem(inp);
		Workbook wb = new HSSFWorkbook(fs);
		Sheet sheet = wb.getSheetAt(0);
		// 获取列数
		int cellNums = sheet.getRow(0).getLastCellNum();
		int rowIndex = 1;
		Row row = null;
		String cur = null;
		for (AlarmInfo alarmInfo : alarmInfoList) {
				if (rowIndex > maxExportRows + 1) {
					break;
				}
				row=sheet.createRow(rowIndex++);
				for(int j=0;j<cellNums;j++){
					switch(j) {
	                case 0: cur =  String.valueOf(alarmInfo.getAlarmInfoId());break;
	                case 1: if(alarmInfo.getAlarmDetails().contains("frontProcessorId")){
	                	cur = JsonUtil.getJsonObjectValue("frontProcessorId", alarmInfo.getAlarmDetails());
	                }else{
	                	cur = "";
	                };
	                break;
	                case 2: cur =  AlarmInfoController.formatAlarmType(alarmInfo.getAlarmType());break;
	                case 3: cur =  String.valueOf(alarmInfo.getAlarmDetails());break;
	                case 4: cur =  DateUtil.longToString(alarmInfo.getAlarmTime(),"yyyy-MM-dd HH:mm:ss SSS");break;
	                case 5: cur =  alarmInfo.getIsHandle()==0?"否":"是";break;
	            }
					row.createCell(j).setCellValue(cur);
				}
			}
			return wb;
		}
	
	public static String formatLayer(String value) {
		if (value == null || value.equals("null")) return "";
		return value;
	}

	
	public static String  formatLogicChannel(String value) {
		if (value.equals("0")) {
			return "FrequencySpectrum";
		} else if (value.equals("1")) {
			return "SDCCH";
		} else if (value.equals("2")) {
			return "SACCH";
		} else if (value.equals("3")) {
			return "TCH";
		} else if (value.equals("4")) {
			return "SACCH_WITH_TCH";
		} else if (value.equals("5")) {
			return "FACCH";
		}else if (value.equals("6")) {
            return "RACH";
        }
        else if (value.equals("7")) {
            return "BCCH";
        }
        else if (value.equals("8")) {
            return "AGCH";
        }
		return value;
	}
	
	public static String formatSingalName(String signalName) {

		if (signalName == null || signalName.length() < 1 || signalName.equals("null"))
			return "";

		if (!signalName.contains("Message"))
			return signalName;

		String message = signalName.substring(7, 10).trim();

		String result;

		if (message.equals("129")) {
			result = "M" + message + ": " + "Validated Train Data";
		} else if (message.equals("130")) {
			result = "M" + message + ": " + "Request for Shunting";
		} else if (message.equals("132")) {
			result = "M" + message + ": " + "MA Request";
		} else if (message.equals("136")) {
			result = "M" + message + ": " + "Train Position Report";
		} else if (message.equals("137")) {
			result = "M" + message + ": " + "Request to stop earlier is granted";
		} else if (message.equals("138")) {
			result = "M" + message + ": " + "Request to stop earlier is rejected";
		} else if (message.equals("146")) {
			result = "M" + message + ": " + "Acknowledgement";
		} else if (message.equals("147")) {
			result = "M" + message + ": " + "Acknowledgement of Emergency Stop";
		} else if (message.equals("149")) {
			result = "M" + message + ": " + "Track Ahead Free Granted";
		} else if (message.equals("150")) {
			result = "M" + message + ": " + "End of Mission";
		} else if (message.equals("153")) {
			result = "M" + message + ": " + "Radio in-fill request";
		} else if (message.equals("154")) {
			result = "M" + message + ": " + "No compatible version";
		} else if (message.equals("155")) {
			result = "M" + message + ": " + "Initiation of a communication session";
		} else if (message.equals("156")) {
			result = "M" + message + ": " + "Termination of a communication session";
		} else if (message.equals("157")) {
			result = "M" + message + ": " + "SoM Position Report";
		} else if (message.equals("159")) {
			result = "M" + message + ": " + "Session Established";
		} else if (message.equals("2")) {
			result = "M" + message + ": " + "SR Authorisation";
		} else if (message.equals("3")) {
			result = "M" + message + ": " + "Movement Authority";
		} else if (message.equals("6")) {
			result = "M" + message + ": " + "Recognition of exit from TRIP mode";
		} else if (message.equals("8")) {
			result = "M" + message + ": " + "Acknowledgement of Train Data";
		} else if (message.equals("9")) {
			result = "M" + message + ": " + "Request to Stop Earlier";
		} else if (message.equals("15")) {
			result = "M" + message + ": " + "Conditional Emergency Stop";
		} else if (message.equals("16")) {
			result = "M" + message + ": " + "Unconditional Emergency Stop";
		} else if (message.equals("18")) {
			result = "M" + message + ": " + "Revocation of Emergency Stop";
		} else if (message.equals("24")) {
			result = "M" + message + ": " + "General message";
		} else if (message.equals("27")) {
			result = "M" + message + ": " + "SH Refused";
		} else if (message.equals("28")) {
			result = "M" + message + ": " + "SH Authorised";
		} else if (message.equals("33")) {
			result = "M" + message + ": " + "MA with Shifted Location Reference";
		} else if (message.equals("34")) {
			result = "M" + message + ": " + "Track Ahead Free Request";
		} else if (message.equals("37")) {
			result = "M" + message + ": " + "In-fill MA";
		} else if (message.equals("40")) {
			result = "M" + message + ": " + "Train outside controlled area";
		} else if (message.equals("32")) {
			result = "M" + message + ": " + "Configuration Determination";
		} else if (message.equals("38")) {
			result = "M" + message + ": " + "Initiation of a communication session";
		} else if (message.equals("39")) {
			result = "M" + message + ": " + "Acknowledgement of termination of a communication session";
		} else if (message.equals("41")) {
			result = "M" + message + ": " + "Train Accepted";
		} else if (message.equals("43")) {
			result = "M" + message + ": " + "SoM position report confirmed by RBC";
		} else if (message.equals("45")) {
			result = "M" + message + ": " + "Assignment of coordinate system";
		} else {
			result = message;
		}
		return result;
	}
	
	public static String formatDirection(String value) {
		if(value.equals("0")){
			return "上行";
		} else {
			return "下行";
		}
	}
	
	public static String formatDirection1(String value) {
		if (value.equals("0")) {
			return "下行";
		} else {
			return "上行";
		}
	}

	public static String tchFormatDirection(String value) {
		if (value.equals("1")) {
			return "ATP->RBC";
		} else {
			return "RBC->ATP";
		}
	}

	public static String formatGServiceType(int value) {
		if (value == 5) {
			return "列车无线车次号校核信息";
		} else if (value == 6) {
			return "调度命令信息";
		} else if (value == 7) {
			return "列车停稳/启动信息";
		} else if (value == 14) {
			return "M-GRIS IP地址查询/更新/响应信息";
		} else if (value == 15) {
			return "GRIS IP地址查询/更新/响应信息";
		} else if (value == 34) {
			return "站场车号商检信息";
		} else if (value == 36) {
			return "站场调车作业单信息";
		} else if (value == 241) {
			return "GPRS终端活动性检测信息";
		} else if (value == 18) {
			return "TCDS信息";
		} else if (value == 48) {
			return "DMS信息";
		} else if (value == 160) {
			return "机车信号远程监控信息";
		} else if (value == 10) {
			return "工务晃车信息";
		} else if (value == 12) {
			return "RMD信息";
		} else if (value == 4) {
			return "列尾风压信息";
		} else if (value == 19) {
			return "GIR出入库检测信息";
		} else {
			return Integer.toString(value);
		}
	}
	
	private static String formatGFunctionCode(int gFunctionCode) {
		if (gFunctionCode == 1) {
			return "调度命令";
		} else if (gFunctionCode == 2) {
			return "路票";
		} else if (gFunctionCode == 3) {
			return "绿色许可证";
		} else if (gFunctionCode == 4) {
			return "红色许可证";
		} else if (gFunctionCode == 5) {
			return "出站跟踪调车通知书";
		} else if (gFunctionCode == 17) {
			return "调车作业通知单";
		} else if (gFunctionCode == 18) {
			return "调车请求确认";
		} else if (gFunctionCode == 32) {
			return "出入库检查";
		} else if (gFunctionCode == 7) {
			return "列车进路预告信息";
		} else if (gFunctionCode >= 24 && gFunctionCode <= 31) {
			return "其它消息";
		} else {
			return Integer.toString(gFunctionCode);
		}
	}
	
	private static String formatGOrder(int value) {
		if (value == 1) {
			return "GPRS终端活动性检测";
		} else if (value == 2) {
			return "GPRS终端活动性检测响应";
		} else if (value == 32) {
			return "列车进路预告";
		} else if (value == 51) {
			return "调度命令自动确认";
		} else if (value == 53) {
			return "调度命令手动签收";
		}
		return Integer.toString(value);
	}
	public static void fillExcelData_GPRS_full(List<GPRS_full> gprs_fullList, Workbook wb, String[] headers) {
		int rowIndex = 0;
		String cur = null;
		Sheet sheet = wb.createSheet();
		Row row = sheet.createRow(rowIndex++);
		for (int i = 0; i < headers.length; i++) {
			row.createCell(i).setCellValue(headers[i]);
		}
		for (GPRS_full gprs_full : gprs_fullList) {
			if (rowIndex > maxExportRows + 1) {
				break;
			}
			row=sheet.createRow(rowIndex++);
			for (int j = 0; j < headers.length; j++) {
				switch (j) {
                case 0: cur =  gprs_full.getStartTime();break;
                case 1: cur =  gprs_full.getIMSI();break;
                case 2: cur =  gprs_full.getMSISDN();break;
                case 3: cur =  gprs_full.getTLLI();break;
                case 4: cur =  gprs_full.getgTrainNo();break;
                case 5: cur =  gprs_full.getgEngineNo();break;
                case 6: cur =  gprs_full.getBSName();break;
                case 7: cur =  String.valueOf(gprs_full.getBCCH());break;
                case 8: cur =  String.valueOf(gprs_full.getTCH());break;
                case 9: cur =  String.valueOf(gprs_full.getTimeSlot());break;
                case 10: cur =  String.valueOf(gprs_full.getUSF());break;
                case 11: cur =  String.valueOf(gprs_full.getTFI());break;
                case 12: cur =  String.valueOf(gprs_full.getFrameNumber());break;
                case 13: cur =  gprs_full.getDirection();break;
                case 14: cur =  gprs_full.getMessageType();break;
                case 15: cur =  gprs_full.getDataLayer();break;
                case 16: cur =  gprs_full.getSourceIP();break;
                case 17: cur =  gprs_full.getDestinationIP();break;
                case 18: cur =  gprs_full.getgSourceIP();break;
                case 19: cur =  gprs_full.getgDstIP();break;
                case 20: cur =  formatGServiceType(gprs_full.getgServiceType());break;
                case 21: cur =  formatGOrder(gprs_full.getgOrder());break;
                case 22: cur =  StringUtil.isEmpty(gprs_full.getgData()) ? gprs_full.getDecoded() : gprs_full.getgData();break;
                case 23: cur =  gprs_full.getgDispatchCode();break;
                case 24: cur =  String.valueOf(gprs_full.getDataLength());break;
                case 25: cur =  gprs_full.getLEVEL();break;
                case 26: cur =  gprs_full.getSNR();break;
                case 27: cur =  gprs_full.getQUALITY();break;
                case 28: cur =  gprs_full.getSourceCode();break;
                case 29: cur =  String.valueOf(gprs_full.getLAC());break;
                case 30: cur =  String.valueOf(gprs_full.getCI());break;
                case 31: cur =  String.valueOf(gprs_full.getFrontProcessorID());break;
                case 32: cur =  String.valueOf(gprs_full.getFileNo());break;
                }
				row.createCell(j).setCellValue(cur);
			}
		}
	}

	public static Workbook fillExcelDataWithTemplate_GPRS_full(List<GPRS_full> gprs_fullList, String templateFileName) throws Exception {
		InputStream inp = ExcelUtil.class.getResourceAsStream("/com/gsmr/template/" + templateFileName);
		POIFSFileSystem fs = new POIFSFileSystem(inp);
		Workbook wb = new HSSFWorkbook(fs);
		Sheet sheet = wb.getSheetAt(0);
		// 获取列数
		int cellNums = sheet.getRow(0).getLastCellNum();
		int rowIndex = 1;
		Row row = null;
		String cur = null;
		for (GPRS_full gprs_full : gprs_fullList) {
			if (rowIndex > maxExportRows + 1) break;

			row = sheet.createRow(rowIndex++);
			for (int j = 0; j < cellNums; j++) {
				switch (j) {
                case 0: cur =  gprs_full.getStartTime();break;
                case 1: cur =  gprs_full.getIMSI();break;
                case 2: cur =  gprs_full.getTLLI();break;
                case 3: cur =  gprs_full.getMSISDN();break;
                case 4: cur =  String.valueOf(gprs_full.getFrontProcessorID());break;
                case 5: cur =  String.valueOf(gprs_full.getLAC());break;
                case 6: cur =  String.valueOf(gprs_full.getCI());break;
                case 7: cur =  gprs_full.getBSName();break;
                case 8: cur =  String.valueOf(gprs_full.getBCCH());break;
                case 9: cur =  String.valueOf(gprs_full.getTCH());break;
                case 10: cur =  String.valueOf(gprs_full.getTimeSlot());break;
                case 11: cur =  gprs_full.getDirection();break;
                case 12: cur =  String.valueOf(gprs_full.getFrameNumber());break;
                case 13: cur =  gprs_full.getMessageType();break;
                case 14: cur =  gprs_full.getDataLayer();break;
                case 15: cur =  gprs_full.getSourceIP();break;
                case 16: cur =  gprs_full.getDestinationIP();break;
                case 17: cur =  gprs_full.getSourceCode();break;
                case 18: cur =  String.valueOf(gprs_full.getDataLength());break;
                case 19: cur =  gprs_full.getSourceIP();break;
                case 20: cur =  String.valueOf(gprs_full.getgSrcPortFrame());break;
                case 21: cur =  gprs_full.getgDstIP();break;
                case 22: cur =  String.valueOf(gprs_full.getgDstPortFrame());break;
                case 23: cur =  String.valueOf(gprs_full.getgServiceType());break;
                case 24: cur =  String.valueOf(gprs_full.getgOrder());break;
                case 25: cur =  gprs_full.getgData();break;
                case 26: cur =  String.valueOf(gprs_full.getgGoodCRC());break;
                case 27: cur =  gprs_full.getgEngineNo();break;
                case 28: cur =  gprs_full.getgTrainNo();break;
                }
				row.createCell(j).setCellValue(cur);
			}
		}
		return wb;
	}
	
	public static void fillExcelData_GPRS_default(List<GPRS_default> gprs_defaultList, Workbook wb, String[] headers) {
		int rowIndex = 0;
		String cur = null;
		Sheet sheet = wb.createSheet();
		Row row = sheet.createRow(rowIndex++);
		for (int i = 0; i < headers.length; i++) {
			row.createCell(i).setCellValue(headers[i]);
		}
		for(GPRS_default gprs_default : gprs_defaultList){
			if (rowIndex > maxExportRows + 1) break;
			
			row=sheet.createRow(rowIndex++);
			for (int j = 0; j < headers.length; j++) {
				switch(j){

				case 0: cur =  gprs_default.getStartTime();break;
                case 1: cur =  gprs_default.getIMSI();break;
                case 2: cur =  gprs_default.getTLLI();break;
                case 3: cur =  String.valueOf(gprs_default.getBCCH());break;
                case 4: cur =  String.valueOf(gprs_default.getTCH());break;
                case 5: cur =  String.valueOf(gprs_default.getTimeSlot());break;
                case 6: cur =  gprs_default.getUSF();break;
                case 7: cur =  gprs_default.getTFI();break;
                case 8: cur =  String.valueOf(gprs_default.getFrameNumber());break;
                case 9: cur =  gprs_default.getBSName();break;
                case 10: cur =  gprs_default.getDirection();break;
                case 11: cur =  gprs_default.getgEngineNo();break;
                case 12: cur =  gprs_default.getgTrainNo();break;
                case 13: cur =  gprs_default.getMessageType();break;
                case 14: cur =  gprs_default.getDataLayer();break;
                case 15: cur =  gprs_default.getSourceIP();break;
                case 16: cur =  gprs_default.getDestinationIP();break;
                case 17: cur =  gprs_default.getDecoded();break;
                case 18: cur =  String.valueOf(gprs_default.getDataLength());break;
                case 19: cur =  gprs_default.getLEVEL();break;
                case 20: cur =  gprs_default.getSNR();break;
                case 21: cur =  gprs_default.getQUALITY();break;
                case 22: cur =  gprs_default.getSourceCode();break;
                case 23: cur =  String.valueOf(gprs_default.getLAC());break;
                case 24: cur =  String.valueOf(gprs_default.getCI());break;
                case 25: cur =  String.valueOf(gprs_default.getFrontProcessorID());break;
                case 26: cur =  String.valueOf(gprs_default.getFileNo());break;
                }
				row.createCell(j).setCellValue(cur);
			}
		}
	}
	

	public static Workbook fillExcelDataWithTemplate_GPRS_default(List<GPRS_default> gprs_defaultList, String templateFileName) throws Exception {
		InputStream inp = ExcelUtil.class.getResourceAsStream("/com/gsmr/template/" + templateFileName);
		POIFSFileSystem fs = new POIFSFileSystem(inp);
		Workbook wb = new HSSFWorkbook(fs);
		Sheet sheet = wb.getSheetAt(0);
		// 获取列数
		int cellNums = sheet.getRow(0).getLastCellNum();
		int rowIndex=1;
		Row row = null;
		String cur = null;
		for(GPRS_default gprs_default : gprs_defaultList){
			if (rowIndex > maxExportRows + 1) break;
			
			row=sheet.createRow(rowIndex++);
			for(int j=0;j<cellNums;j++){
				switch(j){ 
				case 0: cur =  String.valueOf(gprs_default.getId());break;
                case 1: cur =  String.valueOf(gprs_default.getFileNo());break;
                case 2: cur =  gprs_default.getTimeStamp();break;
                case 3: cur =  gprs_default.getIMSI();break;
                case 4: cur =  gprs_default.getTLLI();break;
                case 5: cur =  gprs_default.getMSISDN();break;
                case 6: cur =  gprs_default.getStartTime();break;
                case 7: cur =  String.valueOf(gprs_default.getFrontProcessorID());break;
                case 8: cur =  String.valueOf(gprs_default.getBCCH());break;
                case 9: cur =  String.valueOf(gprs_default.getTCH());break;
                case 10: cur =  String.valueOf(gprs_default.getTimeSlot());break;
                case 11: cur =  gprs_default.getDirection();break;
                case 12: cur =  String.valueOf(gprs_default.getFrameNumber());break;
                case 13: cur =  gprs_default.getMessageType();break;
                case 14: cur =  gprs_default.getDataLayer();break;
                case 15: cur =  gprs_default.getSourceIP();break;
                case 16: cur =  gprs_default.getDestinationIP();break;
                case 17: cur =  gprs_default.getSourceCode();break;
                case 18: cur =  gprs_default.getDecoded();break;
                case 19: cur =  gprs_default.getgEngineNo();break;
                case 20: cur =  gprs_default.getgTrainNo();break;
                case 21: cur =  gprs_default.getGkmMark();break;
                }
				row.createCell(j).setCellValue(cur);
			}
		}
		return wb;
	}

	public static void fillExcelData_SDCCH_FACCH(List<SDCCH_FACCH> sdcch_facchList, Workbook wb, String[] headers) {
		int rowIndex = 0;
		String cur = null;
		Sheet sheet = wb.createSheet();
		Row row = sheet.createRow(rowIndex++);
		for (int i = 0; i < headers.length; i++) {
			row.createCell(i).setCellValue(headers[i]);
		}
		for(SDCCH_FACCH sdcch_FACCH : sdcch_facchList){
			if (rowIndex > maxExportRows + 1) break;
			
			row=sheet.createRow(rowIndex++);
			for (int j = 0; j < headers.length; j++) {
				switch(j){

                    case 0:
                        cur = DateUtil.longToString(Long.parseLong(sdcch_FACCH.getStartTime()), "yyyy-MM-dd HH:mm:ss SSS");
                        break;
//                case 1: cur =  sdcch_FACCH.getIMSI();break;
//                case 2: cur =  sdcch_FACCH.getMSISDN();break;
                    case 1:
                        cur = sdcch_FACCH.getCTCS_ID();
                        break;
                    case 2:
                        cur = sdcch_FACCH.getSiteName();
                        break;
                    case 3:
                        cur = sdcch_FACCH.getBCCH();
                        break;
                    case 4:
                        cur = sdcch_FACCH.getTCH();
                        break;
                    case 5:
                        cur = sdcch_FACCH.getTimeSlot();
                        break;
                    case 6:
                        cur = formatLogicChannel(sdcch_FACCH.getLogicChannel());
                        break;
                    case 7:
                        cur = sdcch_FACCH.getFrameNumber();
                        break;
                    case 8:
                        cur = formatDirection1(sdcch_FACCH.getDirection());
                        break;
                    case 9:
                        cur = sdcch_FACCH.getMessage_TYPE();
                        break;
                    case 10:
                        cur = sdcch_FACCH.getL2();
                        break;
                    case 11:
                        cur = formatKilometer(sdcch_FACCH.getKilometer());
                        break;
                    case 12:
                        cur = sdcch_FACCH.getSpeed();
                        break;
                    case 13:
                        cur = sdcch_FACCH.getDataLength();
                        break;
                    case 14:
                        cur = sdcch_FACCH.getLEVEL();
                        break;
                    case 15:
                        cur = sdcch_FACCH.getSNR();
                        break;
                    case 16:
                        cur = sdcch_FACCH.getQUALITY();
                        break;
                    case 17:
                        cur = sdcch_FACCH.getSourceData();
                        break;
                    case 18:
                        cur = sdcch_FACCH.getDecode();
                        break;
//                case 18: cur =  sdcch_FACCH.getMS_TYPE();break;
//                case 19: cur =  sdcch_FACCH.getTMSI();break;
                    case 19:
                        cur = sdcch_FACCH.getLAC();
                        break;
                    case 20:
                        cur = sdcch_FACCH.getCI();
                        break;
                    case 21:
                        cur = sdcch_FACCH.getFrontProcessorId();
                        break;
                    case 22:
                        cur = sdcch_FACCH.getRecordId();
                        break;
                }
				row.createCell(j).setCellValue(cur);
			}
		}
	}
	
	public static Workbook fillExcelDataWithTemplate_SDCCH_FACCH(List<SDCCH_FACCH> sdcch_facchList, String templateFileName) throws Exception {
		InputStream inp=ExcelUtil.class.getResourceAsStream("/com/gsmr/template/"+templateFileName);
		POIFSFileSystem fs = new POIFSFileSystem(inp);
		Workbook wb=new HSSFWorkbook(fs);
		Sheet sheet=wb.getSheetAt(0);
		// 获取列数
		int cellNums=sheet.getRow(0).getLastCellNum();
		int rowIndex=1;
		Row row = null;
		String cur = null;
		for (SDCCH_FACCH sdcch_facch : sdcch_facchList) {
			if (rowIndex > maxExportRows + 1) break;
			
			row=sheet.createRow(rowIndex++);
			for (int j = 0; j < cellNums; j++) {
				switch(j){ 
                case 0: cur =  DateUtil.longToString(Long.parseLong(sdcch_facch.getStartTime()),"yyyy-MM-dd HH:mm:ss SSS");break;
                case 1: cur =  sdcch_facch.getFrontProcessorId();break;
                case 2: cur =  sdcch_facch.getRecordId();break;
                case 3: cur =  sdcch_facch.getIMSI();break;
                case 4: cur =  formatLogicChannel(sdcch_facch.getLogicChannel());break;
                case 5: cur =  sdcch_facch.getMSISDN();break;
                case 6: cur =  formatDirection(sdcch_facch.getDirection());break;
                case 7: cur =  sdcch_facch.getSiteName();break;
                case 8: cur =  sdcch_facch.getDecode();break;
                case 9: cur =  sdcch_facch.getCI();break;
                case 10: cur =  sdcch_facch.getLAC();break;
                case 11: cur =  sdcch_facch.getCTCS_ID();break;
                case 12: cur =  sdcch_facch.getMS_TYPE();break;
                case 13: cur =  sdcch_facch.getMessage_TYPE();break;
                case 14: cur =  sdcch_facch.getTimeSlot();break;
                case 15: cur =  sdcch_facch.getTMSI();break;
                case 16: cur =  sdcch_facch.getChannel();break;
                case 17: cur =  sdcch_facch.getTCH();break;
                case 18: cur =  sdcch_facch.getL2();break;
                case 19: cur =  sdcch_facch.getDataLength();break;
                case 20: cur =  sdcch_facch.getSourceData();break;
                }
				row.createCell(j).setCellValue(cur);
			}
		}
		return wb;
	}
	
	public static void fillExcelData_SingleUser(List<SingleUser> singleUserList, Workbook wb, String[] headers) {
		int rowIndex=0;
		String cur = null;
		Sheet sheet=wb.createSheet();
		Row row=sheet.createRow(rowIndex++);
		for (int i = 0; i < headers.length; i++) {
			row.createCell(i).setCellValue(headers[i]);
		}
		for(SingleUser singleUser : singleUserList){
			if (rowIndex > maxExportRows + 1)  break;
			
			row=sheet.createRow(rowIndex++);
			for (int j = 0; j < headers.length; j++) {
				switch (j) {
	                case 0: cur =  DateUtil.longToString(Long.parseLong(singleUser.getStartTime()),"yyyy-MM-dd HH:mm:ss SSS");break;
	                case 1: cur =  singleUser.getIMSI();break;
	                case 2: cur =  singleUser.getMSISDN();break;
	                //case 3: cur =  singleUser.getTrainNumber();break;
	                case 3: cur =  singleUser.getCTCS_ID();break;
	                case 4: cur =  singleUser.getSiteName();break;
				case 5:
					cur = formatDirection1(singleUser.getDirection());
					break;
	                case 6: cur =  formatLogicChannel(singleUser.getLogicChannel());break;
	                case 7: cur =  formatSingalName(singleUser.getSubType());break;
	                case 8: cur =  singleUser.getCRCTest();break;
				case 9:
					cur = formatKilometer(singleUser.getKilometer());
					break;
	                case 10: cur =  singleUser.getSpeed();break;
                    case 11: cur =  singleUser.getDataLength();break;
                    case 12: cur =  singleUser.getLEVEL();break;
                    case 13: cur =  singleUser.getSNR();break;
                    case 14: cur =  singleUser.getQUALITY();break;
                    case 15: cur =  singleUser.getData();break;
	                case 16: cur =  singleUser.getRecordId();break;
                }
				row.createCell(j).setCellValue(cur);
			}
		}
	}
	
	private static String formatKilometer(String value) {
//		if (value == null || value.length() < 5)
//			return value;
//		String start = value.substring(0, 4);
//		String end = value.substring(4, 7);
//		return 'k' + start + '+' + end;
		if(value != null) {
			if(value.length() > 3) {
				String start = value.substring(0,value.length()-3);
				String end = value.substring(value.length()-3, value.length());
				return "k" + start + "+" + end;
			}
		}
		return value;
	}

	public static Workbook fillExcelDataWithTemplate_SingleUser(List<SingleUser> singleUserList, String templateFileName) throws Exception {
		InputStream inp=ExcelUtil.class.getResourceAsStream("/com/gsmr/template/"+templateFileName);
		POIFSFileSystem fs = new POIFSFileSystem(inp);
		Workbook wb=new HSSFWorkbook(fs);
		Sheet sheet=wb.getSheetAt(0);
		// 获取列数
		int cellNums=sheet.getRow(0).getLastCellNum();
		int rowIndex=1;
		Row row = null;
		String cur = null;
		for(SingleUser singleUser : singleUserList){
			if (rowIndex > maxExportRows + 1) {
				break;
			}
			row=sheet.createRow(rowIndex++);
			for(int j=0;j<cellNums;j++){
				switch(j){ 
                case 0: cur =  DateUtil.longToString(Long.parseLong(singleUser.getStartTime()),"yyyy-MM-dd HH:mm:ss SSS");break;
                case 1: cur =  singleUser.getMSISDN();break;
                case 2: cur =  singleUser.getTrainNumber();break;
                case 3: cur =  singleUser.getCTCS_ID();break;
                case 4: cur =  formatDirection(singleUser.getDirection());break;
				case 5:
					cur = formatKilometer(singleUser.getKilometer());
					break;
                case 6: cur =  singleUser.getSpeed();break;
                case 7: cur =  formatLogicChannel(singleUser.getLogicChannel());break;
                case 8: cur =  singleUser.getSubType();break;
                case 9: cur =  singleUser.getCRCTest();break;
                case 10: cur =  singleUser.getData();break;
                case 11: cur =  singleUser.getDataLength();break;
                case 12: cur =  singleUser.getSiteName();break;
                }
				try {
					row.createCell(j).setCellValue(cur);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		return wb;
	}
	
	public static void fillExcelData_InterferenceQuery(List<Interference> interference_all, Workbook wb, String[] headers) {
		int rowIndex=0;
		String cur = null;
		Sheet sheet=wb.createSheet();
		Row row=sheet.createRow(rowIndex++);
		for(int i=0;i<headers.length;i++){
			row.createCell(i).setCellValue(headers[i]);
		}
		for(Interference interference : interference_all){
			if (rowIndex > maxExportRows + 1) {
				break;
			}
			row=sheet.createRow(rowIndex++);
			for(int j=0;j<headers.length;j++){
				switch(j) {
				case 0: cur =  interference.getAlarmLevel();break;
                case 1: cur =  interference.getFrontId();break;
                case 2: cur =  interference.getBSName();break;
                case 3: cur =  interference.getTimeBegin();break;
                case 4: cur =  interference.getTimeEnd();break;
                case 5: cur =  interference.getDirection();break;
                case 6: cur =  interference.getEngineID();break;
                case 7: cur =  interference.getKilometer();break;
                case 8: cur =  interference.getInfIntensity();break;
                case 9: cur =  interference.getInfBandWidth();break;
                case 10: cur =  interference.getInfProbability();break;
                case 11: cur =  interference.getInfChannel();break;
                case 12: cur =  interference.getInfMaxChannel();break;
                case 13: cur =  interference.getInfSecChannel();break;
                case 14: cur =  interference.getInfType();break;
                case 15: cur =  interference.getInfSourceType();break;
                case 16: cur =  interference.getDisposed();break;
                case 17: cur =  interference.getReleaseWay();break;
                case 18: cur =  interference.getReleaseTime();break;
                }
				try {
					row.createCell(j).setCellValue(cur);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
    public static void fillExcelData_InterferenceOccuryQuery(List<InterfaceOccupy> interference_all, Workbook wb, String[] headers) {
        int rowIndex=0;
        String cur = null;
        Sheet sheet=wb.createSheet();
        Row row=sheet.createRow(rowIndex++);
        for(int i=0;i<headers.length;i++){
            row.createCell(i).setCellValue(headers[i]);
        }
        for(InterfaceOccupy interference : interference_all){
            if (rowIndex > maxExportRows + 1) {
                break;
            }
            row=sheet.createRow(rowIndex++);
            for(int j=0;j<headers.length;j++){
                switch(j) {
                    case 0: cur =  interference.getBSName();break;
                    case 1: cur =  interference.getDirection();break;
                    case 2: cur =  interference.getInfMaxChannel();break;
                    case 3: cur =  interference.getInfIntensity();break;
                    case 4: cur =  interference.getDiff();break;
                    case 5: cur =  interference.getOffest();break;
                    case 6: cur =  interference.getInfpercentage();break;
                }
                try {
                    row.createCell(j).setCellValue(cur);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    }

	public static void fillExcelData_NetworkAnalysis(List<Index> indexList, Workbook wb, String[] headers) {
		int rowIndex = 0;
		String cur = null;
		Sheet sheet = wb.createSheet();
		Row row = sheet.createRow(rowIndex++);
		for (int i = 0; i < headers.length; i++) {
			row.createCell(i).setCellValue(headers[i]);
		}
		for (Index index : indexList) {
			if (rowIndex > maxExportRows + 1) {
				break;
			}
			row = sheet.createRow(rowIndex++);
			for (int j = 0; j < headers.length; j++) {
				switch (j) {
				case 0:
					cur = index.getBsName();
					break;
				case 1:
					cur = index.getBsCI();
					break;
				case 2:
					cur = index.getDate();
					break;
				case 3:
					cur = index.getTimeslot();
					break;
				case 4:
					cur = index.getIndex_name();
					break;
				case 5:
					cur = index.getIndex_num();
					break;
				case 6:
					cur = index.getIndex_deno();
					break;
				case 7:
					cur = index.getIndex_value();
					break;
				}
				try {
					row.createCell(j).setCellValue(cur);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}

	public static void fillExcelData_InterferenceAlarm(List<AlarmHistoryExport> interference_all, Workbook wb, String[] headers) {
		int rowIndex = 0;
		String cur = null;
		Sheet sheet = wb.createSheet();
		Row row = sheet.createRow(rowIndex++);
		for (int i = 0; i < headers.length; i++) {
			row.createCell(i).setCellValue(headers[i]);
		}
		for (AlarmHistoryExport interference : interference_all) {
			if (rowIndex > maxExportRows + 1) {
				break;
			}
			row = sheet.createRow(rowIndex++);
			for (int j = 0; j < headers.length; j++) {
				switch (j) {
				case 0:
					cur = interference.getAlarmLevel();
					break;
				case 1:
					cur = interference.getFrontId();
					break;
				case 2:
					cur = interference.getBSName();
					break;
				case 3:
					cur = interference.getTimeBegin();
					break;
				case 4:
					cur = interference.getTimeStamp();
					break;
				case 5:
					cur = interference.getDirection();
					break;
				case 6:
					cur = interference.getInfIntensity();
					break;
				case 7:
					cur = interference.getInfChannel();
					break;
				case 8:
					cur = interference.getInfType();
					break;
				case 9:
					cur = interference.getInfSourceType();
					break;
				case 10:
					cur = interference.getIsDisposed();
					break;
				}
				try {
					row.createCell(j).setCellValue(cur);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}
}